home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / DOCINDEX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  2.6 KB  |  98 lines

  1. /*  docindex.c - index a new document */
  2. #include   "stdio.h"
  3. #include   "cminor.h"
  4. #include   "document.h"
  5. #include   "btree.h"
  6. #include   "bt_macro.h"
  7.  
  8. int  compf() ;
  9. int  sizef() ;
  10. #define RW_MODE  2                      /* read & write allowed */
  11. #define EOF_REL  2                      /* seek relative to end-of-file */
  12. long lseek() ;
  13.  
  14. main(argc,argv)
  15.   int   argc ;
  16.   char  *argv[] ;
  17.   {
  18.      int   ret , datfile ;
  19.      char  fn[65] ;
  20.      RECPOS   fs, r ;
  21.      IX_DESC  ixd ;
  22.      DOCUMENT doc ;
  23.  
  24.      if( argc < 2 )
  25.         {  printf(" USAGE:  docindex   doc-file-name \n") ;
  26.            exit(5) ;
  27.         }
  28.  
  29.      add_str(fn,argv[1],".idx") ;
  30.      if( openix(fn,&ixd,compf,sizef) < 0 )
  31.         {  printf(" can't open the index file \n") ;
  32.            exit(10) ;
  33.         }
  34.  
  35.      add_str(fn,argv[1],".dat") ;
  36.      datfile = gopen(fn,RW_MODE,BIN_MODE) ;
  37.      if( datfile < 0 )
  38.         {  printf(" can't open the data file \n") ;
  39.            closeix(&ixd) ;
  40.            exit(12) ;
  41.         }
  42.  
  43.      while( 1 )                         /* collect and index doc. names */
  44.         {  if( input(&doc) <= 0 )       /* get input for next doc. */
  45.               break ;                   /* exit if at end */
  46.            r = lseek(datfile,0L,EOF_REL) ;      /* append the doc. record */
  47.        ret = write(datfile,&doc,sizeof(DOCUMENT) ) ;   /* at EOF */
  48.            if( indexit(&doc,r,&ixd) < 0 )       /* index the document */
  49.               {  printf(" indexing failed \n") ;
  50.                  break ;
  51.               }
  52.         }
  53.      closeix(&ixd) ;
  54.      closeix(datfile) ;
  55.   }
  56.  
  57.  
  58. int  input(pdoc)                        /* get input describing a document */
  59.   DOCUMENT *pdoc ;
  60.   {
  61.      int   ret ;
  62.  
  63.      printf("\n document name (return to quit): ") ;
  64.      ret = getstr(pdoc->dname,NAME_LEN-1) ;
  65.      if( ret <= 0 )
  66.         return( 1 ) ;
  67.      printf(" address to: ") ;
  68.      getstr(pdoc->addressee,ADR_LEN-1) ;
  69.      printf(" date sent (yy/mm/dd): ") ;
  70.      getstr(pdoc->date,DATE_LEN-1) ;
  71.      printf(" subject: ") ;
  72.      getstr(pdoc->subject,SUBJ_LEN-1) ;
  73.      return( 1 ) ;
  74.   }
  75.  
  76. indexit(pdoc,r,pix)                     /* index the document */
  77.   DOCUMENT *pdoc ;
  78.   RECPOS   r ;
  79.   IX_DESC  *pix ;
  80.   {
  81.      ENTRY e ;
  82.  
  83.      e.rptr = r ;
  84.      add_str(e.key,"A*",pdoc->addressee) ;
  85.      if( find_ins(&e,pix) != IX_OK ) ;
  86.         return( -1 ) ;
  87.      add_str(e.key,"D*",pdoc->date) ;
  88.      if( find_ins(&e,pix) != IX_OK ) ;
  89.         return( -1 ) ;
  90.      add_str(e.key,"S*",pdoc->subject) ;
  91.      if( find_ins(&e,pix) != IX_OK ) ;
  92.         return( -1 ) ;
  93.      return( 0 ) ;
  94.   }
  95.  
  96.  
  97.  
  98.